package com.citusdata.elven.httpRpc;

import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;
import org.apache.http.HttpStatus;


public class HttpRpcController implements RpcController {

  protected boolean failed     = false;
  protected String  errorText  = null;
  protected int     httpStatus = HttpStatus.SC_OK;  // OK at init time

  public int httpStatus() {
    return httpStatus;
  }

  public String errorText() {
    return errorText;
  }

  public boolean failed() {
    return failed;
  }

  public void reset() {
    failed     = false;
    errorText  = null;
    httpStatus = HttpStatus.SC_OK;
  }

  public void setFailed(String reason) {
    // Use Internal Server Error as the default error code.
    setFailed(reason, HttpStatus.SC_INTERNAL_SERVER_ERROR);
  }

  public void setFailed(String reason, int code) {
    failed     = true;
    errorText  = reason;
    httpStatus = code;
  }

  public boolean isCanceled() {
    // Not yet supported
    throw new UnsupportedOperationException("Cannot cancel request in HttpRpc");
  }

  public void notifyOnCancel(RpcCallback callback) {
    // Not yet supported
    throw new UnsupportedOperationException("Cannot cancel request in HttpRpc");
  }

  public void startCancel() {
    // Not yet supported
    throw new UnsupportedOperationException("Cannot cancel request in HttpRpc");
  }
}